<template>
	<u18address-list :data2="data" :select="ifselect" @handlerDel="del" @handlerSelect="select"></u18address-list>
	<view class="createAddress" @click="toCAddress" v-if="!ifselect">
		+新建用户地址
	</view>
	<view class="createAddress" v-else @click="back">
		确定
	</view>
</template>

<script setup>
	import {ref} from 'vue'
	import u18addressList from "../components/18addressList.vue"
	import { onLoad } from '@dcloudio/uni-app'
	import http from '../components/http.js'
	const data = ref([])
	const ifselect = ref(undefined)
	onLoad((options)=>{
		ifselect.value = options.select 
	})
	http.http({url:'/address/queryAll',method:'GET'}).then(res=>{
		data.value = res.data.data
	})
	function toCAddress(){
		uni.navigateTo({
			url:'cAddress'
		})
	}
	function del(id){
		http.http({url:'/address/del?id='+id,method:'GET'}).then(res=>{
			setTimeout(()=>{
				http.http({url:'/address/queryAll',method:'GET'}).then(res=>{
					data.value = res.data.data
				})
			},300)
			
		})
	}
	function select(e){
		console.log(e)
		uni.setStorageSync('addressId',e.id)
	}
	function back(){
		uni.navigateBack({
			delta:1
		})
	}
</script>

<style>
	.createAddress{
		width:690rpx;
		height:100rpx;
		position:fixed;
		bottom:30rpx;
		left:30rpx;
		background:red;
		color:#fff;
		line-height:100rpx;
		text-align:center;
		border-radius:30rpx;
	}
</style>